export default {
	//开单费
	sysOpenOrderFreights(createForm, servicePriceData) {
		return servicePriceData.kaipiao_fee;
	},
	//系统操作费
	sysOperateFreights(createForm, servicePriceData) {
		let weight = this.getTotalWeight(createForm);
		let volume = this.getTotalVolume(createForm);
		let interval = this.getInterval(createForm, servicePriceData);
		let money = 0;
		//   'float_ratio':'', //下浮比例
		//interval 1标准价 2计算价格
		if (interval == 1) {
			money = servicePriceData.caozuo_fee0;
		} else if (interval == 2) {
			let weight_money = Number(weight) * Number(servicePriceData.caozuo_fee1);
			let volume_money = Number(volume) * Number(servicePriceData.caozuo_fee2);

			if (weight_money > volume_money) {
				money = weight_money;
			} else {
				money = volume_money;
			}
		} else {
			money = servicePriceData.caozuo_fee0;
		}
		// console.log("money----" + money); 
		if (isNaN(money)) {
			return 0;
		} else {
			return parseFloat(money).toFixed(2);
		}
	},

	//重量体积区间
	getInterval(createForm, servicePriceData) {
		let weight = this.getTotalWeight(createForm);
		let volume = this.getTotalVolume(createForm);
		let interval = 0;
		if (Number(weight) < Number(servicePriceData.caozuo_weight) && Number(volume) < Number(servicePriceData
				.caozuo_volume)) {
			interval = 1;
		} else {
			interval = 2;
		}
		// console.log("interval----" + interval);
		return interval;
	},
	// 获取总重量
	getTotalWeight(createForm) {
		let weight = 0;
		let arr = createForm.goods;
		for (let i = 0; i < arr.length; i++) {
			if (isNaN(arr[i].total_weight)) {
				weight += 0;
			} else {
				weight += Number(arr[i].total_weight);
			}
		}
		// console.log("weight----" + weight);
		return weight;
	},
	// 获取总体积
	getTotalVolume(createForm) {
		let volume = 0;
		let arr = createForm.goods;
		for (let i = 0; i < arr.length; i++) {
			if (isNaN(arr[i].total_volume)) {
				volume += 0;
			} else {
				volume += Number(arr[i].total_volume);
			}
		}
		// console.log("volume----" + volume);
		return volume;
	}
}